package com.yxdj.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yxdj.user.api.domain.Address;
import com.yxdj.user.mapper.AddressMapper;
import com.yxdj.user.service.IAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户地址信息Service业务层处理
 *
 * @author mty
 * @date 2025-03-18
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements IAddressService
{
    @Autowired
    private AddressMapper addressMapper;

    /**
     * 查询用户地址信息
     *
     * @param id 用户地址信息主键
     * @return 用户地址信息
     */
    @Override
    public Address selectAddressById(Long id)
    {
        return addressMapper.selectAddressById(id);
    }

    /**
     * 查询用户地址信息列表
     *
     * @param address 用户地址信息
     * @return 用户地址信息
     */
    @Override
    public List<Address> selectAddressList(Address address)
    {
        return addressMapper.selectAddressList(address);
    }

    /**
     * 新增用户地址信息
     *
     * @param address 用户地址信息
     * @return 结果
     */
    @Override
    public int insertAddress(Address address)
    {
        return addressMapper.insertAddress(address);
    }

    /**
     * 修改用户地址信息
     *
     * @param address 用户地址信息
     * @return 结果
     */
    @Override
    public int updateAddress(Address address)
    {
        return addressMapper.updateAddress(address);
    }

    /**
     * 批量删除用户地址信息
     *
     * @param ids 需要删除的用户地址信息主键
     * @return 结果
     */
    @Override
    public int deleteAddressByIds(Long[] ids)
    {
        return addressMapper.deleteAddressByIds(ids);
    }

    /**
     * 删除用户地址信息信息
     *
     * @param id 用户地址信息主键
     * @return 结果
     */
    @Override
    public int deleteAddressById(Long id)
    {
        return addressMapper.deleteAddressById(id);
    }

    @Override
    public List<Address> getUserAddressByUserId(Long userId) {
        return baseMapper.selectList(new LambdaQueryWrapper<Address>().eq(Address::getUserId,userId));
    }

    @Override
    public Address getAddressById(Long id) {
        return baseMapper.getAddressById(id);
    }
}
